import pymysql

class Mysql(object):
    def __init__(self):
        try:
            self.conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='testdb')
            self.cursor = self.conn.cursor()  # 用来获得python执行Mysql命令的方法（游标操作）
            print("连接数据库成功")
        except:
            print("连接失败")

    def ys_t(self):
        sql= "select year,amount from ys_t"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items

    def xmsj_t(self):
        sql= "select commname,rate from xmsj_t"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items

    def kmys_t(self):
        sql= "select costname,amount from kmys_t"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items

    def lnsj_t(self):
        sql= "select year,rate from lnsj_t"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items

    def gysj_t(self):
        sql= "select month,amount,rate from gysj_t"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items

    def xjlpm_t(self):
        sql= "select commname,amount from xjlpm_t order by amount"    #获取数据表的内容
        self.cursor.execute(sql)
        items = self.cursor.fetchall()  #接收全部的返回结果行
        self.conn.close()
        self.cursor.close()
        return items
